/*
 * @Author: orc
 * @we_chat: orc_develop
 * @qq群: 790373986
 * @LastEditors: orc
 * @Description: 
 * @Date: 2019-03-18 17:17:08
 * @LastEditTime: 2019-03-22 10:43:27
 */

import orc from "../../orc";
export default class local_data{    
    public static user_name:string = '';
    public static user_image:string = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1548331587797&di=bed1763eba5a18d1f3bd5df5cbe81ed0&imgtype=0&src=http%3A%2F%2Fbpic.588ku.com%2Felement_origin_min_pic%2F01%2F31%2F87%2F96573b585a7c9c4.jpg';
    public static user_id:string = ''; 
    public static user_old_flag:boolean = false;
    public static sound_music_switch:boolean = true;
    public static sound_effect_switch:boolean = true;
    public static sound_music_volume:number = 0.8;
    public static sound_effect_volume:number = 0.8;    

    /*存取本地数据 */
    public static save_local_data(){
        let save_data:any = {};
        let session_key =  "orc_" + orc.game_config.Platform + "_" + orc.game_config.GAME_NAME;
        save_data[session_key] = {};
        
        for (const key in orc.local_data) {
            save_data[session_key][key] = orc.local_data[key];
        }
        console.log("save_local_data:",save_data);

        cc.sys.localStorage.setItem(session_key,JSON.stringify(save_data[session_key]));
    }

    /*读取本地数据 */
    public static async load_local_data(){  
        console.log('load_local_data');
        let session_key =  "orc_" + orc.game_config.Platform + "_" + orc.game_config.GAME_NAME;           
        let local_data_temp = await cc.sys.localStorage.getItem(session_key);         
        if(local_data_temp == "" || local_data_temp == null)
        {
            //数据为空
            console.log('session_key',session_key,local_data_temp);
        }
        else
        {
            let local_data = JSON.parse(local_data_temp);      
            console.log("load_local_data:",JSON.parse(local_data_temp)); 
            //讲本地的数据存入到local_data里去
            for (const key in local_data) {
                orc.local_data[key] = local_data[key];
            }         
        } 
    }   
}